<template>
  <div style="height: 100%; overflow: hidden">
    <!--    <el-button @click="click">click</el-button> background-color="rgb(48, 65, 86)-->
<!--    background-color="rgb(48, 65, 86)"-->
    <el-menu
        v-for="(item, index) in routesGroup"
        v-show="findPath2($route.path, item.menuTreeList)"
        :default-active="$route.path"
        style="width:244px; height: 100%; "
        background-color="#eee"
        text-color="#000"
        router
    >

      <!--      <el-submenu index="1">-->
      <!--        <template slot="title"><i class="el-icon-message"></i>主页</template>-->
      <!--        <el-menu-item-group>-->
      <!--          <template slot="title">分组一</template>-->
      <!--          <el-menu-item index="/welcome" >主页</el-menu-item>-->
      <!--          <el-menu-item index="/city" style="display: none">city</el-menu-item>-->
      <!--          <el-menu-item index="/ryxx" >人员基本信息</el-menu-item>-->
      <!--          <el-menu-item index="/yjssQx" >油井实时曲线</el-menu-item>-->
      <!--          <el-menu-item index="/zb" >指标下载</el-menu-item>-->
      <!--          <el-menu-item index="/user" >用户管理</el-menu-item>-->
      <!--          <el-menu-item index="/role" >角色管理</el-menu-item>-->
      <!--          <el-menu-item index="/menu" >菜单管理</el-menu-item>-->
      <!--        </el-menu-item-group>-->
      <!--        <el-menu-item-group title="分组2">-->
      <!--          <el-menu-item index="1-3">选项3</el-menu-item>-->
      <!--        </el-menu-item-group>-->
      <!--        <el-submenu index="/city">-->
      <!--          <template slot="title">选项4</template>-->
      <!--          <el-menu-item index="/about">关于。。。</el-menu-item>-->
      <!--        </el-submenu>-->
      <!--      </el-submenu>-->
      <Menubar v-for="item in item.menuTreeList" parentpath="" :item="item"></Menubar>
    </el-menu>
  </div>
</template>

<script>
import Menubar from "@/components/Menubar.vue";
import {dyroutesGroup} from "@/router";

export default {
  data() {
    return {
      routesGroup: dyroutesGroup,
      //淘汰，未使用，暂时没用
      dyroutes1: null
    }
  },
  components: {Menubar},
  //淘汰，未使用，暂时没用
  created() {
    for (let i = 0; i < dyroutesGroup.length; i++) {
      if (this.findPath(this.$route.path, dyroutesGroup[i].menuTreeList)) {
        this.dyroutes1 = dyroutesGroup[i].menuTreeList
        break
      }
    }
  },
  //淘汰，未使用，暂时没用
  watch: {
    $route(newv, oldv) {
      for (let i = 0; i < dyroutesGroup.length; i++) {
        if (this.findPath(this.$route.path, dyroutesGroup[i].menuTreeList)) {
          this.dyroutes1 = dyroutesGroup[i].menuTreeList
          break
          // console.log(this.dyroutes1)
        }
      }
    },
  },
  computed: {
    // routes() {
    //   return this.$router.options.routes
    // }
  },
  methods: {
    findPath2(path, routes) {
      let pathArr = path.split('/')
      // console.log(pathArr)
      if (pathArr[0] == '')
        pathArr.shift()
      for (let i = 0; i < routes.length; i++) {
        let pathTmp = routes[i].path
        if (pathTmp[0] == '/')
          pathTmp = pathTmp.substring(1)
        if (pathArr[0] == pathTmp) {
          return true
        }
      }
      return false
    }
    ,
    findPath(path, routes) {
      let pathArr = path.split('/')
      // console.log(pathArr)
      if (pathArr[0] == '')
        pathArr.shift()
      let routesTmp = routes
      for (let j = 0; j < pathArr.length; j++) {
        let find = false
        if (routesTmp == null)
          return false
        for (let i = 0; i < routesTmp.length; i++) {
          let pathTmp = routesTmp[i].path
          if (pathTmp[0] == '/')
            pathTmp = pathTmp.substring(1)
          if (pathArr[j] == pathTmp) {
            find = true
            routesTmp = routesTmp[i].children
            break
          }
        }
        if (!find)
          return false
      }
      return true;
    },
    click() {
      console.log(this.$router.getRoutes())
    },
    handleSelect() {
      // console.log(this.$router)
    }
  }
}
</script>

<style scoped>

</style>
